home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume9 / uemacs3.8b / part13 < prev    next >
Encoding:
Internet Message Format  |  1987-03-16  |  43.0 KB

  1. Subject:  v09i045:  MicroEMACS, version 3.8b, Part13/14
  2. Newsgroups: mod.sources
  3. Approved: rs@mirror.TMC.COM
  4.  
  5. Submitted by: ihnp4!itivax!duncan!lawrence (Daniel Lawrence)
  6. Mod.sources: Volume 9, Issue 45
  7. Archive-name: uemacs3.8b/Part13
  8.  
  9. #! /bin/sh
  10. # This is a shell archive.  Remove anything before this line,
  11. # then unpack it by saving it in a file and typing "sh file".
  12. # If this archive is complete, you will see the message:
  13. #        "End of archive 13 (of 14)."
  14. # Contents:  main.c
  15. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  16. echo shar: Extracting \"main.c\" \(41443 characters\)
  17. if test -f main.c ; then 
  18.   echo shar: Will not over-write existing file \"main.c\"
  19. else
  20. sed "s/^X//" >main.c <<'END_OF_main.c'
  21. X/*
  22. X *    MicroEMACS 3.8
  23. X *             written by Dave G. Conroy.
  24. X *            greatly modified by Daniel M. Lawrence
  25. X *
  26. X *    (C)opyright 1987 by Daniel M. Lawrence
  27. X *    MicroEMACS 3.8 can be copied and distributed freely for any
  28. X *    non-commercial purposes. MicroEMACS 3.8 can only be incorporated
  29. X *    into commercial software with the permission of the current author.
  30. X *
  31. X * This file contains the main driving routine, and some keyboard processing
  32. X * code, for the MicroEMACS screen editor.
  33. X *
  34. X * REVISION HISTORY:
  35. X *
  36. X * 1.0  Steve Wilhite, 30-Nov-85
  37. X *      - Removed the old LK201 and VT100 logic. Added code to support the
  38. X *        DEC Rainbow keyboard (which is a LK201 layout) using the the Level
  39. X *        1 Console In ROM INT. See "rainbow.h" for the function key defs
  40. X *      Steve Wilhite, 1-Dec-85
  41. X *      - massive cleanup on code in display.c and search.c
  42. X *
  43. X * 2.0  George Jones, 12-Dec-85
  44. X *      - Ported to Amiga.
  45. X *
  46. X * 3.0  Daniel Lawrence, 29-Dec-85
  47. X *      - rebound keys/added new fast buffered I/O for AMIGA
  48. X *    - added META- repeat commands
  49. X *    - added reposition default to center screen (yeah!)
  50. X *    - changed exit with modified buffers message
  51. X *    - made filesave tell us what it is doing
  52. X *    - changed search string entry to terminate with <ESC>
  53. X *      so we can use <NL> in search/replace strings
  54. X *    - updated version number in mode line to 3.0
  55. X *    12-Jan-86
  56. X *    - Added code to reconize the Search/replace functions
  57. X *    - Added code to perform search/replace & query functions
  58. X *    14-Jan-86
  59. X *    - moved search logic to separate function in search.c
  60. X *    - added replace and query replace functions
  61. X *    - separated out control key expansions to be used by others in search.c
  62. X *    15-Jan-86
  63. X *    - changed "visiting" to finding
  64. X *    - changed yes/no responces to not need return
  65. X *    - cleaned up various messages
  66. X *    16-jan-86
  67. X *    - fixed spurious spawn message in MSDOS
  68. X *    - added ^X-S synonime to save command
  69. X *    - moved escape to shell to ^X-C
  70. X *    21-jan-86
  71. X *    - added code to suspend shell under BSD
  72. X *    22-jan-86
  73. X *    - added function key support (SPEC) under MSDOS
  74. X *    - Abort now prints [Aborted] on message line
  75. X *    23-jan-86
  76. X *    - Added modes and commends to set/unset them
  77. X *    24-jan-86
  78. X *    - Added Goto Line command
  79. X *    - added Rename Buffer command
  80. X *    28-jan-86
  81. X *    - added goto beginning and end of paragraph commands (META-P/META-N)
  82. X *    - re-wrote kdelete to use realloc. gained MUCH speed here when
  83. X *      doing large wipes both on UNIX and MSDOS. Changed kill buffer
  84. X *      allocation block size from 256 bytes to 1 k
  85. X *    29-jan-86
  86. X *    - moved extern function declarations to efunc.h
  87. X *    - made name[] name binding table
  88. X *    30-jan-86
  89. X *    - fixed Previous/Next paragraph command not to wrap around EOF
  90. X *    - added Fill Paragraph command (META-Q)
  91. X *    4-feb-86
  92. X *    - added code to properly display long lines, scrolling them right
  93. X *      to left
  94. X *    5-feb-85
  95. X *    - rewrote code to right/left scroll...much better
  96. X *    - added shifted arror keys on IBMPC
  97. X *    6-feb-85
  98. X *    - add option to allow forword-word to jump to beginning of
  99. X *      next word instead of end of current one. This is different from
  100. X *      other emacs' but can be configured off in estruct.h
  101. X *    - added VIEW mode to allow a buffer to be read only
  102. X *       (-v switch on command line will activate this)
  103. X *    - changed quick exit to write out ALL changed buffers!!!
  104. X *      MAKE SURE YOU KNOW THIS WHEN META-Zing
  105. X *    10-feb-86
  106. X *    - added handling of lines longer than allowed on file read in
  107. X *      (they wrap on additional lines)
  108. X *    - made having space clear the message line and NOT insert itself
  109. X *      a configuration option in ed.h
  110. X *    11-feb-86
  111. X *    - added Describe-command and Help commands.
  112. X *    13-feb-86
  113. X *    - added View file command (^X ^V) and finished HELP command
  114. X *    14-feb-86
  115. X *    - added option to let main loop skip update if type ahead commands
  116. X *       are queued up
  117. X *    16-feb-86
  118. X *    - added Insert File command
  119. X *    17-feb-86
  120. X *    - added scroll next window up/down commands
  121. X *    18-feb-86
  122. X *    - added CMODE indentation
  123. X *    - re-arranged header files to standerdize extern and global
  124. X *      definitions
  125. X *    - changed version number to 3.2
  126. X *    - added numeric arguments to search, reverse search and
  127. X *      search and replace
  128. X *    24-feb-86
  129. X *    - added Bind To Key function (^C for now) to allow the user
  130. X *      to change his command keys
  131. X *    - added Unbind key function (M-^C for now)
  132. X *    - added execute named command to execute unbound commands (M-X)
  133. X *    - added describe bindings command (not bound)
  134. X *    - changed version number to 3.3
  135. X *    25-feb-86
  136. X *    - scrapped CERROR mode (too many compilers)
  137. X *    - added EXACT mode for case sensitive searchers
  138. X *    26-feb-86
  139. X *    - added command completion on execute named command and
  140. X *      all routined grabbing a command name
  141. X *    - adding execute-command-line command and its support functions
  142. X *      (in preporation for sourcing files)
  143. X *    - added Execute Buffer command
  144. X *    27-feb-86
  145. X *    - added execute(source) file command and added code to automatically
  146. X *      execute emacs.rc (or .emacsrc on UNIX) before initial read in
  147. X *    - changed version number to 3.4
  148. X *    4-mar-86
  149. X *    - changed word delete to be consistant with word move (it gets
  150. X *      rid of the inter word space now) This is configurable with the
  151. X *      NFWORD symbol in estruct.h
  152. X *    - added B_ACTIVE entry to the buffer table. Let emacs read multiple
  153. X *      file names from the command line and only read them in as needed
  154. X *    5-mar-85
  155. X *    - rewrote command line parser to get rid of my patchy code
  156. X *    - changed version number to 3.5
  157. X *    1-apr-86
  158. X *    - added support for Aztec C 3.20e under MSDOS
  159. X *    - fixed bug in mlwrite on ADM3's and thier ilk under V7
  160. X *    - added insertion of pounds in column one under CMODE
  161. X *    - changed version number to 3.6
  162. X *    3-apr-86
  163. X *    - added next-buffer command (^X-X)
  164. X *    5-apr-86
  165. X *    - added kill paragraph command (M-^W)
  166. X *    - changed fill-paragraph to leave 2 spaces after a period at the
  167. X *      end of a word.
  168. X *    - added OVERWRITE mode
  169. X *    7-apr-86
  170. X *    - fixed overwrite mode to handle tabs
  171. X *    8-apr-86
  172. X *    - added add/delete global mode (<ESC>M & <ESC> ^M) commands
  173. X *    9-apr-86
  174. X *    - added insert space command
  175. X *    - moved bindings around        ^C    insert space
  176. X *                    M-K    bind-to-key
  177. X *                    INSERT    insert space
  178. X *                    DELETE    forwdel
  179. X *    - added hunt forward and hunt reverse commands
  180. X *    10-apr-86
  181. X *    - fixed bug in DOBUF with non-terminated command string
  182. X *    15-apr-86
  183. X *    - fixed tab expansion bug in DISPLAY which hung the AMIGA
  184. X *      (send in by Dawn Banks)
  185. X *    - fixed curcol problen if forwline/backline during keyboard
  186. X *      macro execution (sent in by Ernst Christen)
  187. X *    - added AMIGA function/cursor key support
  188. X *    - fixed nonterminating <NL> replacement bug
  189. X *    - fixed word wrapping problems
  190. X *    16-apr-86
  191. X *    - updated documentation and froze development for 3.6 net release
  192. X *    23-apr-86    version 3.6a
  193. X *    - added forground and background colors. Setable with the
  194. X *      add mode commands for the moment
  195. X *    24-apr-86
  196. X *    - added command to pipe CLI output to a buffer
  197. X *    25-apr-86
  198. X *    - added Dana Hoggat's code to replace lattice's sick system()
  199. X *      function, now we no longer care what the switchar is.
  200. X *    - cleaned up the positioning on several of the spawing commands
  201. X *    26-apr-86
  202. X *    - added a output flush in vttidy(). Unix really appreciates this.
  203. X *    - added filter-buffer (^X#) command to send a buffer through
  204. X *      a dos filter
  205. X *    - made automatic CMODE on .c and .h file compilation dependant
  206. X *      in estruct.h
  207. X *    1-may-86
  208. X *    - optimized some code in update(). It certainly need a lot more.
  209. X *    - added AZTEC profiling capabilities. These are conditional on
  210. X *      the APROF symbol in estruct.h
  211. X *    2-may-86
  212. X *    - added (u)ndo command in query-replace. undoes last repalce.
  213. X *    6-may-86
  214. X *    - re-orginized and wrote the update() function in display.c
  215. X *      now my color hacks are in the right places and the code can be
  216. X *      understood.
  217. X *    [Released version 3.6f for BETA test sites]
  218. X *    8-may-86
  219. X *    - fixed bug in new display routine to wrap cursor on extended
  220. X *      lines at the right time
  221. X *    - modified the buffer-position command to give reasonable info
  222. X *    9-may-86
  223. X *    - improved the word wrap algorithm as not to discard non-space
  224. X *      delimiters. The backscan now looks for white space rather than
  225. X *      !inword().
  226. X *    [Released version 3.6g to Krannert]
  227. X *    10-may-86
  228. X *    - Added IBMPC.C an IBM-PC specific display driver. This makes paging
  229. X *      4-6 times faster. Also made some conditional changes to DISPLAY.C
  230. X *      to eliminate the pscreen[] if using the PC driver.
  231. X *    [changed version number to 3.6i]
  232. X *    12-may-86
  233. X *    - added delete-window (^X 0) command to dispose of a single window
  234. X *    - fixed problem with multiple prefixes from a command line which
  235. X *      was reported by John Gamble
  236. X *    14-may-86
  237. X *    - Added AZTEC support for the IBMPC display driver. Had to
  238. X *      readjust some includes and defines for this.
  239. X *    - fixed bug in delete-window.
  240. X *    - fixed some bizarre behavior with the cursor after coming back
  241. X *      from spawn calls.
  242. X *    [changed version number to 3.7 Freezing development for net release]
  243. X *    15-may-86
  244. X *    - (that didn't last long...) Added execute-macro-(1 thru 20) commands
  245. X *      to execute macro buffers (named "[Macro nn]")
  246. X *    - changed BFTEMP to BFINVS and cleaned up treatment of invisable
  247. X *      buffers.
  248. X *    16-may-86
  249. X *    - added store-macro (unbound) to store any executed command lines to
  250. X *      macro buffer.
  251. X *    - added clear-message-line (unbound) command to do just that
  252. X *    - added resize-window command to change a window's size to the
  253. X *      specified argument
  254. X *    - improved help's logic not to re-read the file if it was already
  255. X *      in a buffer
  256. X *    - added MAGIC mode to all structures and command tables, but the
  257. X *      regular expression code that John Gamble is writting is not ready.
  258. X *    18-may-86
  259. X *    - added interactive prompt requests in command line execution. IE
  260. X *      while executing a macro, a parameter starting with an at sign (@)
  261. X *      causes emacs to prompt with the rest of the parameter and return
  262. X *      the resulting input as the value of the parameter.
  263. X *    - added arguments to split-current-window to force the cursor into
  264. X *      the upper or lower window.
  265. X *    20-may-86
  266. X *    - added support for the Microsoft C compiler as per the changes
  267. X *      send in by Oliver Sharp
  268. X *    - made some upgrades and fixes for VMS sent in by Guy Streeter
  269. X *    21-may-86
  270. X *    - fixed an AZTEC bug in ttgetc by clearing the upper byte
  271. X *    - fixed buf in CMODE with #preprocesser input (bug fix submitted by
  272. X *      Willis of unknown path)
  273. X *    - added support of alternative startup file ( @<filename> ) in
  274. X *      the command line
  275. X *    - added ^Q quoting in interactive input (mlreplyt()).
  276. X *    - added re-binding of meta-prefix and ctlx-prefix
  277. X *    22-may-86
  278. X *    - reorginize getkey routines to make more sense and let prefix
  279. X *      binding work properly.
  280. X *    23-may-86
  281. X *    - checked new code on BSD4.2 made a few fixes
  282. X *    - added optional fence matching while in CMODE
  283. X *    - added goto and search command line arguments by Mike Spitzer
  284. X *    26-may-86
  285. X *    - added parameter fetching from buffers
  286. X *    27-may-86
  287. X *    - fixed some HP150 bugs......
  288. X *    31-may-86
  289. X *    - Added Wang PC keyboard support from modifications by
  290. X *      Sid Shapiro @ Wang Institute
  291. X *    - Fixed some reverse video bugs with code submitted by Peter Chubb
  292. X *    - Fixed bug in nextbuffer reported by Dave Forslund
  293. X *    - added system V support (USG) from Linwood Varney
  294. X *    2-jun-86
  295. X *    - changed defines to just define one unix define (for example,
  296. X *      just define BSD for Unix BSD 4.2)
  297. X *    - Added Incremental search functions written by D. R. Banks
  298. X *      in file ISEARCH.C
  299. X *    - added insert-string (unbound) command to help the macro
  300. X *      language out.
  301. X *    - added unmark-buffer (M-~) command to turn off the current buffers
  302. X *      change flag
  303. X *    - fixed nxtarg to truncate strings longer than asked for max length
  304. X *    4-jun-86
  305. X *    - added special characters in command line tokens. Tidle (~) is
  306. X *      the special leadin character for "nrtb".
  307. X *    - Fixed bad ifdef in aztec code so it could look at HOME dir
  308. X *      for startup, help, and emacs.rc files
  309. X *    6-jun-86
  310. X *    - make delete word commands clear the kill buffer if not after another
  311. X *      kill command
  312. X *    11-jun-86
  313. X *    - made ~@ in string arguments pass as char(192) to nxtarg() so one can
  314. X *      quote @ at the beginning of string arguments
  315. X *    - changed buffer size vars in listbuffers() to long (for big files)
  316. X *    - re-wrote buffer-position command to be much faster
  317. X *    12-jun-86
  318. X *    - added count-words (M-^C) command to count the words/chars and
  319. X *      lines in a region
  320. X *    - changed regions so they could be larger than 65535 (short ->
  321. X *      long in the REGION structure)
  322. X *    - changed ldelete() and all callers to use a long size. The kill
  323. X *      buffer will still have a problem >65535 that can not be solved
  324. X *      until I restructure it.
  325. X *    - grouped paragraph commands and word count together under symbol
  326. X *      WORDPRO to allow them to be conditionally made (or not)
  327. X *    13-jun-86
  328. X *    - re-wrote kill buffer routines again. Now they support an unlimited
  329. X *      size kill buffer, and are (in theory) faster.
  330. X *    - changed delete-next-word (M-D) to not eat the newline after a word,
  331. X *      instead it checks and eats a newline at the cursor.
  332. X *    17-jun-85
  333. X *    - added numeric argument to next/previous-window to access the nth
  334. X *      window from the top/bottom
  335. X *    - added support for the data General 10 MSDOS machine
  336. X *    - added save-window (unbound) and restore-window (unbound) commands
  337. X *      for the use of the menu script. Save-window remembers which window
  338. X *      is current, and restore-window returns the cursor to that window.
  339. X *    20-jun-86
  340. X *    - fixed a bug with the fence matching locking up near the beginning
  341. X *    of a buffer
  342. X *    - added argument to update to selectivaly force a complete update
  343. X *    - added update-screen (unbound) command so macros can force a
  344. X *      screen update
  345. X *    21-jun-86
  346. X *    - rearranged token() and nxtarg() calls so that command names and
  347. X *      repeat counts could also be prompted and fetched from buffers
  348. X *      [this broke later with the exec re-write....]
  349. X *    - added write-message (unbound) command to write out a message
  350. X *      on the message line (for macros)
  351. X *    - changed ifdef's so that color modes are reconized as legal in
  352. X *      b/w version, and simply do nothing (allowing us to use the same
  353. X *      script files)
  354. X *    [Released version 3.7 on July 1 to the net and elswhere]
  355. X *    2-jul-86
  356. X *    - Changed search string terminator to always be the meta character
  357. X *      even if it is rebound.
  358. X *    3-jul-86
  359. X *    - removed extra calls to set color in startup code. This caused the
  360. X *      original current window always to be the global colors.
  361. X *    7-jul-86
  362. X *    - Fixed bugs in mlreplyt() so to work properly with all terminators
  363. X *      including control and spec characters
  364. X *    22-jul-86
  365. X *    - fixed replaces() so that it will return FALSE properly on the
  366. X *      input of the replacement string.
  367. X *    - added a definition for FAILED as a return type.....
  368. X *    - changed version number to 3.7b
  369. X *    23-jul-86
  370. X *    - fixed o -> 0 problem in termio.c
  371. X *    - made ^U universal-argument re-bindable
  372. X *    - wrote atoi() for systems (like aztec) where it acts screwy
  373. X *    - changed version number to 3.7c
  374. X *    25-jul-86
  375. X *    - make ^G abort-command rebindable
  376. X *    29-jul-86
  377. X *    - added HP110 Portable Computer support
  378. X *    - changed version number to 3.7d
  379. X *    30-jul-86
  380. X *    - Fixed a couple of errors in the new VMS code as pointer
  381. X *      out by Ken Shacklford
  382. X *    - split terminal open/close routines into screen and keyboard
  383. X *      open/close routines
  384. X *    - closed the keyboard during all disk I/O so that OS errors
  385. X *      can be respoded to correctly (especially on the HP150)
  386. X *    - changed version number to 3.7e
  387. X *    31-jul-86
  388. X *    - added label-function-key (unbound) command under symbol FLABEL
  389. X *      (primarily for the HP150)
  390. X *    4-aug-86
  391. X *    - added fixes for MicroSoft C as suggested by ihnp4!ihuxm!gmd1
  392. X *        <<remember to fix [list] deletion bug as reported
  393. X *          by craig@hp-pcd>>
  394. X *    8-aug-86
  395. X *    - fixed beginning misspelling error everywhere
  396. X *    - fixed some more MSC errors
  397. X *    - changed version number to 3.7g
  398. X *    20-aug-86
  399. X *    - fixed CMODE .h scanning bug
  400. X *    - changed version number to 3.7h
  401. X *    30-aug-86
  402. X *    - fixed killing renamed [list] buffer (it can't) as submited
  403. X *      by James Aldridge
  404. X *    - Added code to allow multiple lines to display during
  405. X *      vertical retrace
  406. X *      [total disaster....yanked it back out]
  407. X *    9-sep-86
  408. X *    - added M-A (apropos) command to list commands containing a substring.
  409. X *    - fixed an inefficiency in the display update code submited
  410. X *      by William W. Carlson (wwc@pur-ee)
  411. X *    10-sep-86
  412. X *    - added Dana Hoggatt's code for encryption and spliced it into the
  413. X *      proper commands. CRYPT mode now triggers encryption.
  414. X *    - added -k flag to allow encryption key (no spaces) in command line
  415. X *    14-sep-86
  416. X *    - added missing lastflag/thisflag processing to docmd()
  417. X *    - changed version to 3.7i and froze for partial release via mail
  418. X *      and BBS
  419. X *    05-oct-86
  420. X *    - changed some strcpys in main.c to strncpys as suggested by john
  421. X *      gamble
  422. X *    - replaces search.c and isearch.c with versions modified by
  423. X *      john gamble
  424. X *    10-oct-86
  425. X *    - removed references to lflick....it just won't work that way.
  426. X *    - removed defines LAT2 and LAT3...the code no longer is lattice
  427. X *      version dependant.
  428. X *    14-oct-86
  429. X *    - changed spawn so that it will not not pause if executed from
  430. X *      a command line
  431. X *    15-oct-86
  432. X *    - added argument concatination (+) to the macro parsing
  433. X *    - added [] as fence pairs
  434. X *    16-oct-86
  435. X *    - rewrote all macro line parsing routines and rearranged the
  436. X *      mlreply code. saved .6K!!! and have blazed the path for expanding
  437. X *      the command language.
  438. X *    17-oct-86
  439. X *    - added new keyboard macro routines (plus a new level to the
  440. X *      input character function)
  441. X *    22-oct-86
  442. X *    - improved EGA cursor problems
  443. X *    - added -r (restricted) switch to command line for BBS use
  444. X *    06-nov-86
  445. X *    - fixed terminator declarations from char to int in getarg() and
  446. X *      nxtarg() in exec.c as pointed out by john gamble
  447. X *    07-nov-86
  448. X *    - made wordrap() user callable as wrap-word (M-FNW) and changed
  449. X *      the getckey() routine so that illegal keystrokes (too many
  450. X *      prefixes set) could be used for internal bindings. When word
  451. X *      wrap conditions are met, the keystroke M-FNW is executed. Added
  452. X *      word wrap check/call to newline().
  453. X *    11-nov-86
  454. X *    - added and checked support for Mark Williams C 86
  455. X *    12-nov-86
  456. X *    - added goto-matching-fence (M-^F) command to jump to a matching
  457. X *      fence "({[]})" or beep if there is none. This can reframe the
  458. X *      screen.
  459. X *    - added code and structure elements to support change-screen-size
  460. X *      command (M-^S) to change the number of lines being used by
  461. X *      MicroEMACS.
  462. X *    15-nov-86
  463. X *    - finished debuging change-screen-size
  464. X *    17-nov-86
  465. X *    - Encorporated in James Turner's modifications for the Atari ST
  466. X *        23-sep-86
  467. X *        - added support for the Atari ST line of computers (jmt)
  468. X *        --added a '\r' to the end of each line on output and strip
  469. X *          it on input for the SHOW function from the desktop
  470. X *        --added 3 new mode functions (HIREZ, MEDREZ, and LOREZ); chgrez
  471. X *          routine in TERM structure; and MULTREZ define in estructs.h
  472. X *          to handle multiple screen resolutions
  473. X *    [note....ST still not running under lattice yet...]
  474. X *    25-nov-86
  475. X *    - Made the filter-buffer (^X-#) command not work on VIEW mode
  476. X *      buffers
  477. X *    - Made the quick-exit (M-Z) command throw out a newline after 
  478. X *      each message so they could be seen.
  479. X *    26-nov-86
  480. X *    - fixed a couple of bugs in change-screen-size (M-^S) command
  481. X *    - changed file read behavior on long lines and last lines
  482. X *      with no newline (it no longer throws the partial line out)
  483. X *    - [as suggested by Dave Tweten] Made adding a ^Z to the end
  484. X *      of an output file under MSDOS configurable under the
  485. X *      CTRLZ symbol in estruct.h
  486. X *    - [Dave Tweten] Spawn will look up the "TMP" environment variable
  487. X *      for use during various pipeing commands.
  488. X *    - [Dave Tweten] changed pipe command under MSDOS to use '>>'
  489. X *      instead of '>'
  490. X *    04-dec-86
  491. X *    - moved processing of '@' and '#' so that they can be outside
  492. X *      the quotes in an argument, and added hooks to process '%' for
  493. X *      environment and user variables.
  494. X *    - modified ibmpc.c to sence the graphics adapter (CGA and MONO)
  495. X *      at runtime to cut down on the number of versions.
  496. X *    05-dec-86
  497. X *    - changed macro directive character to "!" instead of "$" (see
  498. X *      below) and fixed the standard .rc file to comply.
  499. X *    - added code to interpret environment variables ($vars). Added
  500. X *      hooks for built in functions (&func). So, to recap:
  501. X *
  502. X *        @<string>    prompt and return a string from the user
  503. X *        #<buffer name>    get the next line from a buffer and advance
  504. X *        %<var>        get user variable <var>
  505. X *        $<evar>        get environment variable <evar>
  506. X *        &<func>        evaluate function <func>
  507. X *
  508. X *    - allowed repeat counts to be any of the above
  509. X *    - added code to allow insert-string (unbound) to use its
  510. X *      repeat count properly
  511. X *    - added set (^X-A) command to set variables. Only works on
  512. X *      environmental vars yet.
  513. X *    9-dec-86
  514. X *    - added some code for user defined variables...more to come
  515. X *    - added options for malloc() memory pool tracking
  516. X *    - preliminary user variables (%) working
  517. X *    - changed terminal calls to macro's (to prepare for the new
  518. X *      terminal drivers)
  519. X *    15-dec-86
  520. X *    - changed previous-line (^P) and next-line (^N) to return a
  521. X *      FALSE at the end or beginning of the file so repeated
  522. X *      macros involving them terminate properly!
  523. X *    - added code for $CURCOL and $CURLINE
  524. X *    20-dec-86
  525. X *    - set (^X-A) now works with all vars
  526. X *    - added some new functions
  527. X *          &ADD &SUB &TIMES &DIV &MOD &NEG &CAT
  528. X *    - yet again rearranged functions to control macro execution. Did
  529. X *      away with getarg()
  530. X *    23-dec-86
  531. X *    - added string functions
  532. X *          &LEFt &RIGht &MID
  533. X *    31-dec-86
  534. X *    - added many logical functions
  535. X *          &NOT &EQUal &LESs &GREater
  536. X *    - added string functions
  537. X *          &SEQual &SLEss &SGReater
  538. X *    - added variable indirection with &INDirect
  539. X *    - made fixes to allow recursive macro executions
  540. X *      (improved speed during macro execution as well)
  541. X *    3-jan-87
  542. X *    - added $FLICKER to control flicker supression
  543. X *    - made spawn commands restricted
  544. X *    - cleaned up lots of unintentional int<->char problems
  545. X *    4-jan-87
  546. X *    - Fixed broken pipe-command (^X-@) command under MSDOS
  547. X *    - added !IF  !ELSE  !ENDIF  directives and changed the
  548. X *      name of !END to !ENDM....real slick stuff
  549. X *    5-jan-87
  550. X *    - quick-exit (M-Z) aborts on any filewrite errors
  551. X *    8-jan-87
  552. X *    - debugged a lot of the new directive and evaluation code.
  553. X *      BEWARE of stack space overflows! (increasing stack to
  554. X *      16K under MSDOS)
  555. X *    - removed non-standard DEC Rainbow keyboard support...let someone
  556. X *      PLEASE impliment this in the standard manner using key bindings
  557. X *      and send the results to me.
  558. X *    - added change-screen-width () command and $CURWIDTH variable
  559. X *    11-jan-87
  560. X *    - fixed an increadably deeply buried bug in vtputc and combined
  561. X *      it with vtpute (saving about 200 bytes!)
  562. X *    16-jan-87
  563. X *    - added code to handle controling multiple screen resolutions...
  564. X *      allowed the IBM-PC driver to force mono or cga modes.
  565. X *    - added current buffer name and filename variables
  566. X *      $cbufname and $cfname
  567. X *    18-jan-87
  568. X *    - added $sres variable to control screen resolution
  569. X *    - added $debug variable to control macro debugging code (no longer
  570. X *      is this activated by GLOBAL spell mode)
  571. X *    - fixed bug in -g command line option
  572. X *    - Released Version 3.8 to BBSNET
  573. X *    21-jan-87
  574. X *    - added $status variable to record return status of last command
  575. X */
  576. X
  577. X#include        <stdio.h>
  578. X
  579. X/* for MSDOS, increase the default stack space */
  580. X
  581. X#if    MSDOS & LATTICE
  582. Xunsigned _stack = 16536;
  583. X#endif
  584. X
  585. X#if    MSDOS & AZTEC
  586. Xint _STKSIZ = 16536/16;        /* stack size in paragraphs */
  587. Xint _STKRED = 1024;        /* stack checking limit */
  588. Xint _HEAPSIZ = 4096/16;        /* (in paragraphs) */
  589. Xint _STKLOW = 0;        /* default is stack above heap (small only) */
  590. X#endif
  591. X
  592. X/* make global definitions not external */
  593. X#define    maindef
  594. X
  595. X#include        "estruct.h"    /* global structures and defines */
  596. X#include    "efunc.h"    /* function declarations and name table    */
  597. X#include    "edef.h"    /* global definitions */
  598. X#include    "ebind.h"    /* default key bindings */
  599. X
  600. X#if    MEGAMAX
  601. Xoverlay "main"
  602. X#endif
  603. X
  604. X#if     VMS
  605. X#include        <ssdef.h>
  606. X#define GOOD    (SS$_NORMAL)
  607. X#endif
  608. X
  609. X#ifndef GOOD
  610. X#define GOOD    0
  611. X#endif
  612. X
  613. X#if    APROF    /* Declarations needed for AZTEC C profiling */
  614. Xint _Corg();    /* first address of program */
  615. Xint _Cend();    /* last address of program */
  616. X
  617. Xshort monbuf[NBUCK];    /* buffer for gather info */
  618. X#endif
  619. X
  620. Xmain(argc, argv)
  621. Xchar    *argv[];
  622. X{
  623. X        register int    c;
  624. X        register int    f;
  625. X        register int    n;
  626. X        register int    mflag;
  627. X    register BUFFER *bp;
  628. X    register int    ffile;        /* first file flag */
  629. X    register int    carg;        /* current arg to scan */
  630. X    register int    startf;        /* startup executed flag */
  631. X    int basec;            /* c stripped of meta character */
  632. X    int viewflag;            /* are we starting in view mode? */
  633. X        int gotoflag;                   /* do we need to goto a line at start? */
  634. X        int gline;                      /* if so, what line? */
  635. X        int searchflag;                 /* Do we need to search at start? */
  636. X        char bname[NBUFN];        /* buffer name of file to read */
  637. X#if    CRYPT
  638. X    int eflag;            /* encrypting on the way in? */
  639. X    char ekey[NPAT];        /* startup encryption key */
  640. X#endif
  641. X
  642. X#if    APROF
  643. X    /* if we are doing AZTEC C profiling, start it up */
  644. X    /*_intr_sp(18);     set clock interupt for 60/second */
  645. X    monitor(_Corg, _Cend, monbuf, NBUCK, 0);
  646. X#endif
  647. X
  648. X    /* initialize the editor and process the command line arguments */
  649. X        strcpy(bname, "main");    /* default buffer name */
  650. X        vtinit();        /* Displays.            */
  651. X        edinit(bname);        /* Buffers, windows.    */
  652. X    varinit();        /* user variables */
  653. X    viewflag = FALSE;    /* view mode defaults off in command line */
  654. X    gotoflag = FALSE;    /* set to off to begin with */
  655. X    searchflag = FALSE;    /* set to off to begin with */
  656. X    ffile = TRUE;        /* no file to edit yet */
  657. X    startf = FALSE;        /* startup file not executed yet */
  658. X#if    CRYPT
  659. X    eflag = FALSE;        /* no encryption by default */
  660. X#endif
  661. X#if    COLOR
  662. X    curwp->w_fcolor = gfcolor;        /* and set colors    */
  663. X    curwp->w_bcolor = gbcolor;
  664. X#endif
  665. X    
  666. X    /* scan through the command line and get the files to edit */
  667. X    for (carg = 1; carg < argc; ++carg) {
  668. X        /* if its a switch, process it */
  669. X        if (argv[carg][0] == '-') {
  670. X            switch (argv[carg][1]) {
  671. X                case 'v':    /* -v for View File */
  672. X                case 'V':
  673. X                    viewflag = TRUE;
  674. X                    break;
  675. X                case 'e':    /* -e for Edit file */
  676. X                case 'E':
  677. X                    viewflag = FALSE;
  678. X                    break;
  679. X                case 's':    /* -s for initial search string */
  680. X                case 'S':
  681. X                    searchflag = TRUE;
  682. X                    strncpy(pat,&argv[carg][2],NPAT);
  683. X                    break;
  684. X                case 'g':    /* -g for initial goto */
  685. X                case 'G':    
  686. X                    gotoflag = TRUE;
  687. X                    gline = atoi(&argv[carg][2]);
  688. X                    break;
  689. X                case 'r':    /* -r restrictive use */
  690. X                case 'R':
  691. X                    restflag = TRUE;
  692. X                    break;
  693. X#if    CRYPT
  694. X                case 'k':    /* -k<key> for code key */
  695. X                case 'K':
  696. X                    if (argv[carg][2] == 0)
  697. X                        eflag = FALSE;
  698. X                    else {
  699. X                        eflag = TRUE;
  700. X                        strcpy(ekey, &argv[carg][2]);
  701. X                    }
  702. X                    break;
  703. X#endif
  704. X                default:    /* unknown switch */
  705. X                    /* ignore this for now */
  706. X                    break;
  707. X            }
  708. X        } else     /* check for a macro file */
  709. X            if (argv[carg][0]== '@') {
  710. X
  711. X            if (startup(&argv[carg][1]) == TRUE)
  712. X                startf = TRUE;    /* don't execute emacs.rc */
  713. X
  714. X        } else {    /* process a file name */
  715. X            /* if we haven't run emacs.rc, do it now */
  716. X            if (startf == FALSE) {
  717. X                startup("");
  718. X                startf = TRUE;
  719. X#if    COLOR
  720. X                curwp->w_fcolor = gfcolor;
  721. X                curwp->w_bcolor = gbcolor;
  722. X#endif
  723. X            }
  724. X
  725. X            /* set up a buffer for this file */
  726. X                    makename(bname, argv[carg]);
  727. X
  728. X#if    CRYPT
  729. X            /* set up for de-cryption if needed */
  730. X            if (eflag) {
  731. X                curbp->b_mode |= MDCRYPT;
  732. X                strncpy(curbp->b_key, ekey, NPAT);
  733. X                crypt((char *)NULL, 0);
  734. X                crypt(curbp->b_key, strlen(curbp->b_key));
  735. X            }
  736. X#endif
  737. X
  738. X            /* if this is the first file, read it in */
  739. X            if (ffile) {
  740. X                bp = curbp;
  741. X                makename(bname, argv[carg]);
  742. X                strcpy(bp->b_bname, bname);
  743. X                strcpy(bp->b_fname, argv[carg]);
  744. X                if (readin(argv[carg], (viewflag==FALSE))
  745. X                                == ABORT) {
  746. X                    strcpy(bp->b_bname, "main");
  747. X                    strcpy(bp->b_fname, "");
  748. X                }
  749. X                bp->b_dotp = bp->b_linep;
  750. X                bp->b_doto = 0;
  751. X                ffile = FALSE;
  752. X            } else {
  753. X                /* set this to inactive */
  754. X                bp = bfind(bname, TRUE, 0);
  755. X                strcpy(bp->b_fname, argv[carg]);
  756. X                bp->b_active = FALSE;
  757. X            }
  758. X
  759. X            /* set the view mode appropriatly */
  760. X            if (viewflag)
  761. X                bp->b_mode |= MDVIEW;
  762. X        }
  763. X    }
  764. X
  765. X    /* if invoked with nothing, run the startup file here */
  766. X    if (startf == FALSE) {
  767. X        startup("");
  768. X        startf = TRUE;
  769. X#if    COLOR
  770. X        curwp->w_fcolor = gfcolor;
  771. X        curwp->w_bcolor = gbcolor;
  772. X#endif
  773. X    }
  774. X        /* Deal with startup gotos and searches */
  775. X        if (gotoflag && searchflag) {
  776. X            update(FALSE);
  777. X        mlwrite("[Can not search and goto at the same time!]");
  778. X    }
  779. X        else if (gotoflag) {
  780. X                if (gotoline(TRUE,gline) == FALSE) {
  781. X                    update(FALSE);
  782. X            mlwrite("[Bogus goto argument]");
  783. X        }
  784. X        } else if (searchflag) {
  785. X                if (forwhunt(FALSE, 0) == FALSE)
  786. X                    update(FALSE);
  787. X        }
  788. X
  789. X    /* setup to process commands */
  790. X        lastflag = 0;                           /* Fake last flags.     */
  791. X    curbp->b_mode |= gmode;            /* and set default modes*/
  792. X    curwp->w_flag |= WFMODE;        /* and force an update    */
  793. X
  794. Xloop:
  795. X        update(FALSE);                          /* Fix up the screen    */
  796. X        c = getcmd();
  797. X        if (mpresf != FALSE) {
  798. X                mlerase();
  799. X                update(FALSE);
  800. X#if    CLRMSG
  801. X                if (c == ' ')                   /* ITS EMACS does this  */
  802. X                        goto loop;
  803. X#endif
  804. X        }
  805. X        f = FALSE;
  806. X        n = 1;
  807. X
  808. X    /* do META-# processing if needed */
  809. X
  810. X    basec = c & ~META;        /* strip meta char off if there */
  811. X    if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) {
  812. X        f = TRUE;        /* there is a # arg */
  813. X        n = 0;            /* start with a zero default */
  814. X        mflag = 1;        /* current minus flag */
  815. X        c = basec;        /* strip the META */
  816. X        while ((c >= '0' && c <= '9') || (c == '-')) {
  817. X            if (c == '-') {
  818. X                /* already hit a minus or digit? */
  819. X                if ((mflag == -1) || (n != 0))
  820. X                    break;
  821. X                mflag = -1;
  822. X            } else {
  823. X                n = n * 10 + (c - '0');
  824. X            }
  825. X            if ((n == 0) && (mflag == -1))    /* lonely - */
  826. X                mlwrite("Arg:");
  827. X            else
  828. X                mlwrite("Arg: %d",n * mflag);
  829. X
  830. X            c = getcmd();    /* get the next key */
  831. X        }
  832. X        n = n * mflag;    /* figure in the sign */
  833. X    }
  834. X
  835. X    /* do ^U repeat argument processing */
  836. X
  837. X        if (c == reptc) {                  /* ^U, start argument   */
  838. X                f = TRUE;
  839. X                n = 4;                          /* with argument of 4 */
  840. X                mflag = 0;                      /* that can be discarded. */
  841. X                mlwrite("Arg: 4");
  842. X                while ((c=getcmd()) >='0' && c<='9' || c==reptc || c=='-'){
  843. X                        if (c == reptc)
  844. X                if ((n > 0) == ((n*4) > 0))
  845. X                                    n = n*4;
  846. X                            else
  847. X                                n = 1;
  848. X                        /*
  849. X                         * If dash, and start of argument string, set arg.
  850. X                         * to -1.  Otherwise, insert it.
  851. X                         */
  852. X                        else if (c == '-') {
  853. X                                if (mflag)
  854. X                                        break;
  855. X                                n = 0;
  856. X                                mflag = -1;
  857. X                        }
  858. X                        /*
  859. X                         * If first digit entered, replace previous argument
  860. X                         * with digit and set sign.  Otherwise, append to arg.
  861. X                         */
  862. X                        else {
  863. X                                if (!mflag) {
  864. X                                        n = 0;
  865. X                                        mflag = 1;
  866. X                                }
  867. X                                n = 10*n + c - '0';
  868. X                        }
  869. X                        mlwrite("Arg: %d", (mflag >=0) ? n : (n ? -n : -1));
  870. X                }
  871. X                /*
  872. X                 * Make arguments preceded by a minus sign negative and change
  873. X                 * the special argument "^U -" to an effective "^U -1".
  874. X                 */
  875. X                if (mflag == -1) {
  876. X                        if (n == 0)
  877. X                                n++;
  878. X                        n = -n;
  879. X                }
  880. X        }
  881. X
  882. X    /* and execute the command */
  883. X        execute(c, f, n);
  884. X        goto loop;
  885. X}
  886. X
  887. X/*
  888. X * Initialize all of the buffers and windows. The buffer name is passed down
  889. X * as an argument, because the main routine may have been told to read in a
  890. X * file by default, and we want the buffer name to be right.
  891. X */
  892. Xedinit(bname)
  893. Xchar    bname[];
  894. X{
  895. X        register BUFFER *bp;
  896. X        register WINDOW *wp;
  897. X    char *malloc();
  898. X
  899. X        bp = bfind(bname, TRUE, 0);             /* First buffer         */
  900. X        blistp = bfind("[List]", TRUE, BFINVS); /* Buffer list buffer   */
  901. X        wp = (WINDOW *) malloc(sizeof(WINDOW)); /* First window         */
  902. X        if (bp==NULL || wp==NULL || blistp==NULL)
  903. X                exit(1);
  904. X        curbp  = bp;                            /* Make this current    */
  905. X        wheadp = wp;
  906. X        curwp  = wp;
  907. X        wp->w_wndp  = NULL;                     /* Initialize window    */
  908. X        wp->w_bufp  = bp;
  909. X        bp->b_nwnd  = 1;                        /* Displayed.           */
  910. X        wp->w_linep = bp->b_linep;
  911. X        wp->w_dotp  = bp->b_linep;
  912. X        wp->w_doto  = 0;
  913. X        wp->w_markp = NULL;
  914. X        wp->w_marko = 0;
  915. X        wp->w_toprow = 0;
  916. X#if    COLOR
  917. X    /* initalize colors to global defaults */
  918. X    wp->w_fcolor = gfcolor;
  919. X    wp->w_bcolor = gbcolor;
  920. X#endif
  921. X        wp->w_ntrows = term.t_nrow-1;           /* "-1" for mode line.  */
  922. X        wp->w_force = 0;
  923. X        wp->w_flag  = WFMODE|WFHARD;            /* Full.                */
  924. X}
  925. X
  926. X/*
  927. X * This is the general command execution routine. It handles the fake binding
  928. X * of all the keys to "self-insert". It also clears out the "thisflag" word,
  929. X * and arranges to move it to the "lastflag", so that the next command can
  930. X * look at it. Return the status of command.
  931. X */
  932. Xexecute(c, f, n)
  933. X{
  934. X        register KEYTAB *ktp;
  935. X        register int    status;
  936. X
  937. X        ktp = &keytab[0];                       /* Look in key table.   */
  938. X        while (ktp->k_fp != NULL) {
  939. X                if (ktp->k_code == c) {
  940. X                        thisflag = 0;
  941. X                        status   = (*ktp->k_fp)(f, n);
  942. X                        lastflag = thisflag;
  943. X                        return (status);
  944. X                }
  945. X                ++ktp;
  946. X        }
  947. X
  948. X        /*
  949. X         * If a space was typed, fill column is defined, the argument is non-
  950. X         * negative, wrap mode is enabled, and we are now past fill column,
  951. X     * and we are not read-only, perform word wrap.
  952. X         */
  953. X        if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 &&
  954. X        n >= 0 && getccol(FALSE) > fillcol &&
  955. X        (curwp->w_bufp->b_mode & MDVIEW) == FALSE)
  956. X        execute(META|SPEC|'W', FALSE, 1);
  957. X
  958. X        if ((c>=0x20 && c<=0x7E)                /* Self inserting.      */
  959. X        ||  (c>=0xA0 && c<=0xFE)) {
  960. X                if (n <= 0) {                   /* Fenceposts.          */
  961. X                        lastflag = 0;
  962. X                        return (n<0 ? FALSE : TRUE);
  963. X                }
  964. X                thisflag = 0;                   /* For the future.      */
  965. X
  966. X        /* if we are in overwrite mode, not at eol,
  967. X           and next char is not a tab or we are at a tab stop,
  968. X           delete a char forword            */
  969. X        if (curwp->w_bufp->b_mode & MDOVER &&
  970. X            curwp->w_doto < curwp->w_dotp->l_used &&
  971. X            (lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
  972. X             (curwp->w_doto) % 8 == 7))
  973. X                ldelete(1L, FALSE);
  974. X
  975. X        /* do the appropriate insertion */
  976. X        if (c == '}' && (curbp->b_mode & MDCMOD) != 0)
  977. X                status = insbrace(n, c);
  978. X            else if (c == '#' && (curbp->b_mode & MDCMOD) != 0)
  979. X                status = inspound();
  980. X            else
  981. X                    status = linsert(n, c);
  982. X
  983. X#if    CFENCE
  984. X        /* check for CMODE fence matching */
  985. X        if ((c == '}' || c == ')' || c == ']') &&
  986. X                (curbp->b_mode & MDCMOD) != 0)
  987. X            fmatch(c);
  988. X#endif
  989. X
  990. X                lastflag = thisflag;
  991. X                return (status);
  992. X        }
  993. X    TTbeep();
  994. X    mlwrite("[Key not bound]");        /* complain        */
  995. X        lastflag = 0;                           /* Fake last flags.     */
  996. X        return (FALSE);
  997. X}
  998. X
  999. X/*
  1000. X * Fancy quit command, as implemented by Norm. If the any buffer has
  1001. X * changed do a write on that buffer and exit emacs, otherwise simply exit.
  1002. X */
  1003. Xquickexit(f, n)
  1004. X{
  1005. X    register BUFFER *bp;    /* scanning pointer to buffers */
  1006. X    register int status;
  1007. X
  1008. X    bp = bheadp;
  1009. X    while (bp != NULL) {
  1010. X            if ((bp->b_flag&BFCHG) != 0    /* Changed.             */
  1011. X            && (bp->b_flag&BFINVS) == 0) {    /* Real.                */
  1012. X            curbp = bp;        /* make that buffer cur    */
  1013. X            mlwrite("[Saving %s]\n",bp->b_fname);
  1014. X                    if ((status = filesave(f, n)) != TRUE)
  1015. X                        return(status);
  1016. X        }
  1017. X    bp = bp->b_bufp;            /* on to the next buffer */
  1018. X    }
  1019. X        quit(f, n);                             /* conditionally quit   */
  1020. X}
  1021. X
  1022. X/*
  1023. X * Quit command. If an argument, always quit. Otherwise confirm if a buffer
  1024. X * has been changed and not written out. Normally bound to "C-X C-C".
  1025. X */
  1026. Xquit(f, n)
  1027. X{
  1028. X        register int    s;
  1029. X
  1030. X        if (f != FALSE                          /* Argument forces it.  */
  1031. X        || anycb() == FALSE                     /* All buffers clean.   */
  1032. X                        /* User says it's OK.   */
  1033. X        || (s=mlyesno("Modified buffers exist. Leave anyway")) == TRUE) {
  1034. X#if    FILOCK
  1035. X        if (lockrel() != TRUE) {
  1036. X            TTputc('\n');
  1037. X            TTputc('\r');
  1038. X            TTclose();
  1039. X            TTkclose();
  1040. X            exit(1);
  1041. X        }
  1042. X#endif
  1043. X                vttidy();
  1044. X#if    APROF
  1045. X        /* if doing AZTEC C profiling, close up and write it out */
  1046. X        monitor(0,0,0,0,0);
  1047. X#endif
  1048. X                exit(GOOD);
  1049. X        }
  1050. X    mlwrite("");
  1051. X        return (s);
  1052. X}
  1053. X
  1054. X/*
  1055. X * Begin a keyboard macro.
  1056. X * Error if not at the top level in keyboard processing. Set up variables and
  1057. X * return.
  1058. X */
  1059. Xctlxlp(f, n)
  1060. X{
  1061. X        if (kbdmode != STOP) {
  1062. X                mlwrite("%%Macro already active");
  1063. X                return(FALSE);
  1064. X        }
  1065. X        mlwrite("[Start macro]");
  1066. X    kbdptr = &kbdm[0];
  1067. X    kbdend = kbdptr;
  1068. X        kbdmode = RECORD;
  1069. X        return (TRUE);
  1070. X}
  1071. X
  1072. X/*
  1073. X * End keyboard macro. Check for the same limit conditions as the above
  1074. X * routine. Set up the variables and return to the caller.
  1075. X */
  1076. Xctlxrp(f, n)
  1077. X{
  1078. X        if (kbdmode == STOP) {
  1079. X                mlwrite("%%Macro not active");
  1080. X                return(FALSE);
  1081. X        }
  1082. X    if (kbdmode == RECORD) {
  1083. X            mlwrite("[End macro]");
  1084. X            kbdmode = STOP;
  1085. X    }
  1086. X        return(TRUE);
  1087. X}
  1088. X
  1089. X/*
  1090. X * Execute a macro.
  1091. X * The command argument is the number of times to loop. Quit as soon as a
  1092. X * command gets an error. Return TRUE if all ok, else FALSE.
  1093. X */
  1094. Xctlxe(f, n)
  1095. X{
  1096. X        if (kbdmode != STOP) {
  1097. X                mlwrite("%%Macro already active");
  1098. X                return(FALSE);
  1099. X        }
  1100. X        if (n <= 0)
  1101. X                return (TRUE);
  1102. X    kbdrep = n;        /* remember how many times to execute */
  1103. X    kbdmode = PLAY;        /* start us in play mode */
  1104. X    kbdptr = &kbdm[0];    /*    at the beginning */
  1105. X    return(TRUE);
  1106. X}
  1107. X
  1108. X/*
  1109. X * Abort.
  1110. X * Beep the beeper. Kill off any keyboard macro, etc., that is in progress.
  1111. X * Sometimes called as a routine, to do general aborting of stuff.
  1112. X */
  1113. Xctrlg(f, n)
  1114. X{
  1115. X        TTbeep();
  1116. X    kbdmode = STOP;
  1117. X    mlwrite("[Aborted]");
  1118. X        return(ABORT);
  1119. X}
  1120. X
  1121. X/* tell the user that this command is illegal while we are in
  1122. X   VIEW (read-only) mode                */
  1123. X
  1124. Xrdonly()
  1125. X
  1126. X{
  1127. X    TTbeep();
  1128. X    mlwrite("[Key illegal in VIEW mode]");
  1129. X    return(FALSE);
  1130. X}
  1131. X
  1132. Xresterr()
  1133. X
  1134. X{
  1135. X    TTbeep();
  1136. X    mlwrite("[That command is RESTRICTED]");
  1137. X    return(FALSE);
  1138. X}
  1139. X
  1140. Xmeta()    /* dummy function for binding to meta prefix */
  1141. X{
  1142. X}
  1143. X
  1144. Xcex()    /* dummy function for binding to control-x prefix */
  1145. X{
  1146. X}
  1147. X
  1148. Xunarg()    /* dummy function for binding to universal-argument */
  1149. X{
  1150. X}
  1151. X
  1152. X/*****        Compiler specific Library functions    ****/
  1153. X
  1154. X#if    MWC86 & MSDOS
  1155. Xmovmem(source, dest, size)
  1156. X
  1157. Xchar *source;    /* mem location to move memory from */
  1158. Xchar *dest;    /* memory location to move text to */
  1159. Xint size;    /* number of bytes to move */
  1160. X
  1161. X{
  1162. X    register int i;
  1163. X
  1164. X    for (i=0; i < size; i++)
  1165. X        *dest++ = *source++;
  1166. X}
  1167. X#endif
  1168. X
  1169. X#if    RAMSIZE & LATTICE & MSDOS
  1170. X/*    These routines will allow me to track memory usage by placing
  1171. X    a layer on top of the standard system malloc() and free() calls.
  1172. X    with this code defined, the environment variable, $RAM, will
  1173. X    report on the number of bytes allocated via malloc.
  1174. X
  1175. X    with SHOWRAM defined, the number is also posted on the
  1176. X    end of the bottom mode line and is updated whenever it is changed.
  1177. X*/
  1178. X
  1179. X#undef    malloc
  1180. X#undef    free
  1181. X
  1182. Xchar *allocate(nbytes)    /* allocate nbytes and track */
  1183. X
  1184. Xunsigned nbytes;    /* # of bytes to allocate */
  1185. X
  1186. X{
  1187. X    char *mp;    /* ptr returned from malloc */
  1188. X    char *malloc();
  1189. X
  1190. X    mp = malloc(nbytes);
  1191. X    if (mp) {
  1192. X        envram += nbytes;
  1193. X#if    RAMSHOW
  1194. X        dspram();
  1195. X#endif
  1196. X    }
  1197. X
  1198. X    return(mp);
  1199. X}
  1200. X
  1201. Xrelease(mp)    /* release malloced memory and track */
  1202. X
  1203. Xchar *mp;    /* chunk of RAM to release */
  1204. X
  1205. X{
  1206. X    unsigned *lp;    /* ptr to the long containing the block size */
  1207. X
  1208. X    if (mp) {
  1209. X        lp = ((unsigned *)mp) - 1;
  1210. X
  1211. X        /* update amount of ram currently malloced */
  1212. X        envram -= (long)*lp - 2;
  1213. X        free(mp);
  1214. X#if    RAMSHOW
  1215. X        dspram();
  1216. X#endif
  1217. X    }
  1218. X}
  1219. X
  1220. X#if    RAMSHOW
  1221. Xdspram()    /* display the amount of RAM currently malloced */
  1222. X
  1223. X{
  1224. X    char mbuf[20];
  1225. X    char *sp;
  1226. X
  1227. X    TTmove(term.t_nrow - 1, 70);
  1228. X#if    COLOR
  1229. X    TTforg(7);
  1230. X    TTbacg(0);
  1231. X#endif
  1232. X    sprintf(mbuf, "[%lu]", envram);
  1233. X    sp = &mbuf[0];
  1234. X    while (*sp)
  1235. X        TTputc(*sp++);
  1236. X    TTmove(term.t_nrow, 0);
  1237. X    movecursor(term.t_nrow, 0);
  1238. X}
  1239. X#endif
  1240. X#endif
  1241. X
  1242. END_OF_main.c
  1243. if test 41443 -ne `wc -c <main.c`; then
  1244.     echo shar: \"main.c\" unpacked with wrong size!
  1245. fi
  1246. # end of overwriting check
  1247. fi
  1248. echo shar: End of archive 13 \(of 14\).
  1249. cp /dev/null ark13isdone
  1250. MISSING=""
  1251. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do
  1252.     if test ! -f ark${I}isdone ; then
  1253.     MISSING="${MISSING} ${I}"
  1254.     fi
  1255. done
  1256. if test "${MISSING}" = "" ; then
  1257.     echo You have unpacked all 14 archives.
  1258.     echo "See the readme file"
  1259.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1260. else
  1261.     echo You still need to unpack the following archives:
  1262.     echo "        " ${MISSING}
  1263. fi
  1264. ##  End of shell archive.
  1265. exit 0
  1266.